package com.bincloud.vue.admin.common.util;

import com.bincloud.vue.admin.common.exception.CodeMsg;
import com.bincloud.vue.admin.common.model.dto.response.BaseResDTO;

import java.io.Serializable;

/**
 * @Description: 响应工具类
 * @Author: bincloud, mvpzhou
 * @Date: Create By bincloud, mvpzhou on 2022/2/18
 */
@SuppressWarnings("unused")
public class ResponseUtils implements Serializable {

    private ResponseUtils() {}

    /**
     * 状态码
     */
    private String code;
    /**
     * 提示信息
     */
    private String msg;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static <T> BaseResDTO<T> ok() {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(CodeMsg.OK.getCode());
        resDTO.setMsg(CodeMsg.OK.getMsg());
        return resDTO;
    }

    public static <T> BaseResDTO<T> ok(String msg) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(CodeMsg.OK.getCode());
        resDTO.setMsg(msg);
        return resDTO;
    }

    public static <T> BaseResDTO<T> ok(T data) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(CodeMsg.OK.getCode());
        resDTO.setMsg(CodeMsg.OK.getMsg());
        resDTO.setContent(data);
        return resDTO;
    }

    public static <T> BaseResDTO<T> ok(T data, String msg) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(CodeMsg.OK.getCode());
        resDTO.setMsg(msg);
        resDTO.setContent(data);
        return resDTO;
    }

    public static <T> BaseResDTO<T> ok(CodeMsg codeMsg) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(codeMsg.getCode());
        resDTO.setMsg(codeMsg.getMsg());
        return resDTO;
    }

    public static <T> BaseResDTO<T> ok(CodeMsg codeMsg, T data) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(codeMsg.getCode());
        resDTO.setMsg(codeMsg.getMsg());
        resDTO.setContent(data);
        return resDTO;
    }

    public static <T> BaseResDTO<T> fail() {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(CodeMsg.FAIL.getCode());
        resDTO.setMsg(CodeMsg.FAIL.getMsg());
        return resDTO;
    }

    public static <T> BaseResDTO<T> fail(String msg) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(CodeMsg.FAIL.getCode());
        resDTO.setMsg(msg);
        return resDTO;
    }

    public static <T> BaseResDTO<T> fail(String code, String msg) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(code);
        resDTO.setMsg(msg);
        return resDTO;
    }

    public static <T> BaseResDTO<T> fail(CodeMsg codeMsg) {
        BaseResDTO<T> resDTO = new BaseResDTO<>();
        resDTO.setCode(codeMsg.getCode());
        resDTO.setMsg(codeMsg.getMsg());
        return resDTO;
    }
}
